package com.bjpowernode.web.controller;

import com.bjpowernode.commons.model.Page;
import com.bjpowernode.commons.model.Product;
import com.bjpowernode.commons.service.ProductService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController // @Controller+@ResponseBody
@RequestMapping("product")
@CrossOrigin // 允许跨域
public class ProductController{

    @DubboReference(interfaceClass = ProductService.class)
    private ProductService productService;

    @GetMapping("rate")
    public Double getAvgRate() {
        return productService.getAvgRate();
    }

    @GetMapping("index/new")
    public Product getNew() {
        return productService.getNew();
    }

    @GetMapping("index/yx")
    public List getYX() {
        return productService.getYX();
    }

    @GetMapping("index/sb")
    public List getSB() {
        return productService.getSB();
    }

    @GetMapping("{pageNum}/{type}")
    public Page page(@PathVariable Integer pageNum, @PathVariable Integer type) {
        return productService.getPage(pageNum, type);
    }

    @GetMapping("{id}")
    public Product getById(@PathVariable Long id) {
        return productService.getById(id);
    }


}
